# -*- coding: utf-8 -*-
# 创建时间：2021/7/16 17:23
from bs4 import BeautifulSoup
import requests
import time, math, random, json
import pymysql
import re
__author__ = 'LuckyHhy'


def list_extend_insert_append():
    list = [1, 5, 9]
    print("添加元素之前", list, id(list))
    list.append(78)
    print("添加元素之后", list, id(list))
    lis2 = ['454', 'sss']
    # 列表末尾添加多个元素
    list.extend(lis2)  # [1, 5, 9, '454', 'sss']
    print(list)
    # 在任意位置添加多个一个元素
    list.insert(1, 1212)  # [1, 1212, 5, 9]
    print(list)
    list.insert(2, lis2)  # [1, 5, ['454', 'sss'], 9]
    print(list)
    list[2:] = lis2  # 会把后面的元素去掉
    print(list)  # [1, 5, '454', 'sss']


def qie():
    list = [1, 2, 3, 45, 6, 9, 88]
    # 移除列表中的元素，不存在则报错
    # list.remove(3) #[1, 2, 45, 6, 9, 88]
    print(list)
    # 默认移除最后一个
    # list.pop() # [1, 2, 3, 45, 6, 9]
    print(list)
    # 移除指定位置的元素
    # list.pop(1) # [1, 3, 45, 6, 9, 88]
    print(list)
    # 移除指定元素
    # list.remove(1) # [2, 3, 45, 6, 9, 88]
    print(list)
    # 切片 包含头不包含尾
    # list=list[1:3] #[2, 3]
    print(list)
    # 删除整个列表
    # list.clear()
    print(list)


def pp():
    list = [1, 8, 9, 4, 2, 6]
    # 修改指定位置的元素
    # list[2]=88 # [1, 8, 88, 4, 2, 6]
    print(list)
    # 换掉列表的指定元素
    list[1:3] = [55, 66, 77, 88]  # [1, 55, 66, 77, 88, 4, 2, 6]
    print(list)


def sort_list():
    list = [555, 99, 666, 33, 22]
    # 从小到大排序
    # list.sort() #[22, 33, 99, 555, 666]
    print(list)
    # 列表元素翻转
    # list.reverse() #[22, 33, 666, 99, 555]
    print(list)
    # 从大到小排序
    # list.sort(reverse=True) # [666, 555, 99, 33, 22]
    print(list)

    # 产生一个新的列表，原列表不发生变化
    lis = sorted(list, reverse=True)  # [666, 555, 99, 33, 22]
    print(lis)



def list_make():
    list = []
    for i in range(1, 9):
        list.append(i)

    print(list)  # [1, 2, 3, 4, 5, 6, 7, 8]

    # [1, 2, 3, 4, 5, 6, 7, 8, 9]
    lit = [i for i in range(1, 10)]
    print(lit)

    # 列表中元素 2 4 6 8 10
    ll = [i * 2 for i in range(1, 6)]
    print(ll)  # [2, 4, 6, 8, 10]


def main():
    for i in range(1, 9):
        print(i)
    pass


if __name__ == '__main__':
    main()
